import {LRUCache} from 'lru-cache'
let cache = new LRUCache({max:5,ttl:5*1000})

export default {
	data() {
		return {
			isNoMore:false,
			lastNoMoreAt:null,
			listData:[]
		}
	},
	onReachBottom(){
		console.log('onReachBottom')
		
		if(this.isNoMore && this.lastNoMoreAt )
		{
			let delta = Date.now() - this.lastNoMoreAt
			
			console.log(delta)
			
			if(delta < 5 * 1000) return
			
			this.isNoMore = false
			this.lastNoMoreAt = null
		}
		
		this.pushData(this.currentPage + 1)
		
	},
	methods:{
		pushData(page){
			let that = this
			
			this.loadingDay = true
			this.$refs.uToast.show({
				type:"loading",
				show:"true",
				message:"正在加载",
				duration:15000
			})
			
			this.$http.get(`/common/job/task/list?start_date=${this.currentDate}&page=${page}`).then((res)=>{
				console.log(res.data)
				
				if(res.data.length > 0)
				 {
					 that.listData.push(...res.data)
					 that.currentPage = page
				 }else
				 {
					 uni.showToast({
					 	title:'没有更多了',
						icon:'none'
					 })
					 
					 this.isNoMore = true
					 this.lastNoMoreAt = Date.now();
				 }
				
				that.loadingDay = false
				that.$refs.uToast.hide()
			},{
				cache:cache
			})
		},
	}
}